import {
	GridExpViewActionType,
	IGridExpViewAbility,
	IGridExpViewControllerParams,
	IGridExpViewModel,
	IGridExpViewStore,
	IParam,
	IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getExpViewClassNames,
	handleQuickGroupValueChange,
	initExpViewSplit,
	setExpViewSplit,
	useViewAction,
	useViewBasic,
	useViewControllerParams,
	useViewProps,
} from '../use-view';

/**
 * 获取表格导航视图输入参数
 *
 * @export
 * @return {*}
 */
export function useGridExpViewProps() {
	return {
		...useViewProps(),
	};
}

/**
 * 获取表格导航视图基础
 *
 * @export
 * @param {IGridExpViewModel} model 表格导航视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useGridExpViewBasic(model: IGridExpViewModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		return getExpViewClassNames(model, props);
	};
	const initSplit = (instance: any) => {
		if (instance && instance.vnode && instance.vnode.el) {
			return initExpViewSplit(instance.vnode.el as HTMLElement, model) || 0.3;
		}
	};
	const handleSplitChange = (model: any, split: number) => {
		setExpViewSplit(model, split);
	};
	return {
		...useViewBasic(model, props),
		getClassNames,
		initSplit,
		handleSplitChange,
		handleQuickGroupValueChange,
	};
}

/**
 * 表格导航视图行为
 *
 * @export
 */
export function useGridExpViewAction(controller: any) {
	return {
		...useViewAction(controller),
	};
}

/**
 * 获取表格导航视图控制器输入参数
 *
 * @export
 * @param {IGridExpViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<GridExpViewActionType, IGridExpViewAbility>>} evt
 * @return {*}  {IGridExpViewControllerParams<GridExpViewActionType, IGridExpViewAbility>}
 */
export function useGridExpViewControllerParams(
	model: IGridExpViewModel,
	props: IParam,
	evt: QXEvent<IViewEvent<GridExpViewActionType, IGridExpViewAbility>>
): IGridExpViewControllerParams<GridExpViewActionType, IGridExpViewAbility> {
	return {
		...useViewControllerParams<IGridExpViewStore, IGridExpViewModel>(
			model,
			props,
			evt
		),
	};
}
